package com.chat.datea.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chat.datea.R;
import com.chat.datea.bean.RecomNewsMusicEntivity;
import com.squareup.picasso.Picasso;

/**
 * Created by YanBinXie on 15/10/27.
 */
public class NewMusicGridViewAdapter extends BaseAdapter implements View.OnClickListener {
    private Context context;
    private RecomNewsMusicEntivity musicEntivity;


    public NewMusicGridViewAdapter(Context context, RecomNewsMusicEntivity musicEntivity) {
        this.context = context;
        this.musicEntivity = musicEntivity;
    }

    @Override
    public int getCount() {
        return musicEntivity.getPlaze_album_list().getRM().getAlbum_list().getList().size();
    }

    @Override
    public Object getItem(int position) {
        return musicEntivity.getPlaze_album_list().getRM().getAlbum_list().getList().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.newmusic_item, null);
            holder.music_singer = (TextView) convertView.findViewById(R.id.music_singer);
            holder.music_name = (TextView) convertView.findViewById(R.id.music_name);
            holder.play = (ImageView) convertView.findViewById(R.id.play);
            holder.singer_img = (ImageView) convertView.findViewById(R.id.singer_img);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        RecomNewsMusicEntivity.PlazeAlbumListEntity.RMEntity.AlbumListEntity.ListEntity listEntity = (RecomNewsMusicEntivity.PlazeAlbumListEntity.RMEntity.AlbumListEntity.ListEntity) getItem(position);
//        Log.e("NewMusicGridViewAdapter", listEntity.getTitle());
        holder.music_name.setText(listEntity.getTitle());
        holder.music_singer.setText(listEntity.getAuthor());
        holder.play.setOnClickListener(this);
        Picasso.with(context).load(listEntity.getPic_radio()).into(holder.singer_img);
        return convertView;
    }



    private class ViewHolder {
        ImageView singer_img, play;
        TextView music_name, music_singer;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){

        }
    }
}
